package org.NooLab.itexx.app.controller.content;


import java.util.HashMap;
import java.util.Map;

import org.NooLab.utilities.datatypes.ValuePair;
import org.NooLab.utilities.datatypes.ValuePairs;




public class SearchEngine extends AbstractContentAnchors {

	private static final long serialVersionUID = -6945226981824991167L;
	
	
	private boolean isActive;
	private String address;
	private String queryUrl;
	
	Map<String,String> indicatorMap = new HashMap<String,String>();
	
	ValuePairs indicatorList = new ValuePairs();
	
	// ========================================================================
	public SearchEngine(SearchEngines searchEngines){
		super(searchEngines.appCommons);
		
		
	}
	// ========================================================================
	
	
	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}


	public String getName() {
		// 
		return name;
	}


	public void setName(String str) {
		name=str;
	}


	public void setAddress(String str) {
		address = str;
	}


	public void setQueryUrlGenerator(String str) {
		queryUrl = str;
	}


	public void addIndicatorPattern(String indicator, String ivalue) {
		// 
		indicatorMap.put(indicator,ivalue);
		
		indicatorList.add( new ValuePair(indicator,ivalue)) ;
	}


	public String getQueryUrl() {
		return queryUrl;
	}


	public void setQueryUrl(String queryUrl) {
		this.queryUrl = queryUrl;
	}


	public Map<String, String> getIndicatorMap() {
		return indicatorMap;
	}


	public void setIndicatorMap(Map<String, String> indicatorMap) {
		this.indicatorMap = indicatorMap;
	}


	public String getAddress() {
		return address;
	}


	public String getMappedItem(String keystr, boolean relaxed) {
		// 
		String str1,str2,rstr = "";
		
		// problem with map is: no approximate matching
		if (getIndicatorMap().containsKey(keystr)){
			rstr = getIndicatorMap().get(keystr);
		}

		if (relaxed){
			for (int i=0;i<indicatorList.size();i++){
				ValuePair vp = indicatorList.getItem(i);
				str1 = (String) vp.getValue1();
				str2 = (String) vp.getValue2();
				if (str1.contains(keystr)){
					rstr = str2;
					break;
				}
			}// i->
		} // ? relaxed ?
		return rstr ;
	}

	
	
	
}
